/*
 * LinnerLayout.h
 *
 *  Created on: 2012-10-25
 *      Author: yangentao@gmail.com
 */

#ifndef LINNERLAYOUT_H_
#define LINNERLAYOUT_H_

#include "Layout.h"

class LinnerAlign {
public:
	LinnerAlign();
	void center();
	bool isCenter();
protected:
	AlignValue align;
};

class HorLinnerAlign: public LinnerAlign {
public:
	void left();
	void right();
	bool isLeft();
	bool isRight();
};

class VerLinnerAlign: public LinnerAlign {
public:
	void top();
	void bottom();
	bool isTop();
	bool isBottom();
};


class LinnerSizeValue {
public:
	LinnerSizeValue();
	//fill parent
	LinnerSizeValue& fill();
	//fill parent
	bool isFill() const;
	bool isFix() const;
	//fix value
	int fixValue() const;
	//fix value
	void fixValue(int val);

	LinnerSizeValue& limit(int minValue, int maxValue = 0);
private:
	int value;
public:
	int minLimit;//>=0
	int maxLimit;//>=0
};
//TODO width = wrap_content
class LinnerParam: public LayoutParam {
public:

public:
	LinnerParam();
	void check();
public:
	LinnerSizeValue width;
	LinnerSizeValue height;
	HorLinnerAlign hor;
	VerLinnerAlign ver;
	int widthWeight; //>=0, scale in siblings, enable only when width==fill_parent
	int heightWeight; //>=0, scale in siblings, enable only when height==fill_parent
};
class LinnerLayout: public Layout {
public:
	LinnerLayout(bool vertical = false);
public:
	void layout(Window* parent);
private:
	void layoutH(Window* parent);
	void layoutV(Window* parent);
public:
	bool vertical;
};

class HorLinnerLayout: public LinnerLayout{
public:
	HorLinnerLayout();
};
class VerLinnerLayout: public LinnerLayout{
public:
	VerLinnerLayout();
};
//============inline ----implement----------------
inline LinnerSizeValue::LinnerSizeValue() {
	value = 0;
	minLimit = maxLimit = 0;
}
inline LinnerSizeValue& LinnerSizeValue::fill() {
	value = FILL_PARENT;
	return *this;
}
inline bool LinnerSizeValue::isFill() const {
	return value == FILL_PARENT;
}
inline  bool LinnerSizeValue::isFix() const{
	return value >=0;
}
inline int LinnerSizeValue::fixValue() const {
	assert(value >=0);
	return value;
}
inline void LinnerSizeValue::fixValue(int val) {
	assert(val>=0);
	value = val;
}

inline LinnerSizeValue& LinnerSizeValue::limit(int minValue, int maxValue){
	assert(minValue >=0);
	assert(maxValue >=0);
	minLimit= minValue;
	maxLimit = maxValue;
	return *this;
}



inline HorLinnerLayout::HorLinnerLayout(): LinnerLayout(false){

}
inline VerLinnerLayout::VerLinnerLayout(): LinnerLayout(true){

}


inline LinnerParam::LinnerParam() {
	enable = true;
	widthWeight = 0;
	heightWeight = 0;
	type = linnerLayoutParam;
}
inline void LinnerParam::check(){
	assert(widthWeight >=0);
	assert(heightWeight >=0);
}


inline LinnerAlign::LinnerAlign() {
	align = alignCenter;
}
inline void LinnerAlign::center() {
	align = alignCenter;
}
inline bool LinnerAlign::isCenter() {
	return align == alignCenter;
}

inline void HorLinnerAlign::left() {
	align = alignLeft;
}
inline void HorLinnerAlign::right() {
	align = alignRight;
}
inline bool HorLinnerAlign::isLeft() {
	return align == alignLeft;
}
inline bool HorLinnerAlign::isRight() {
	return align == alignRight;
}

inline void VerLinnerAlign::top() {
	align = alignTop;
}
inline void VerLinnerAlign::bottom() {
	align = alignBottom;
}
inline bool VerLinnerAlign::isTop() {
	return align == alignTop;
}
inline bool VerLinnerAlign::isBottom() {
	return align == alignBottom;
}


#endif /* LINNERLAYOUT_H_ */
